// 审核计划表
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="年份" prop="auditYear">
        <el-date-picker
          type="year"
          v-model="queryParams.auditYear"
          format="yyyy"
          value-format="yyyy"
          :style="{ width: '100%' }"
          placeholder="请选择年份"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manageAudit:improvePlan:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manageAudit:improvePlan:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="printBox"
          v-hasPermi="['manageAudit:improvePlan:print']"
          >打印</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      @selection-change="handleSelectionChange"
      fit
      v-loading="loading"
      border
      :data="dataList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column show-overflow-tooltip label="流程状态" min-width="100">
        <template slot-scope="scope">
          <el-tag size="mini">{{ scope.row.statusName }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column min-width="200" show-overflow-tooltip label="年度">
        <template slot-scope="scope">
          <span
            >{{
              scope.row.innerManagerAudit.auditYear
            }}年度管理评审工作计划</span
          >
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="主持人"
        prop="innerManagerAudit.hostName"
        min-width="120"
      />

      <el-table-column
        show-overflow-tooltip
        label="创建人"
        min-width="120"
        prop="createByName"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="240"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['manageAudit:improvePlan:info']"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >

          <!-- <el-button
            v-if="scope.row.status === 'refuse'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manageAudit:improvePlan:edit']"
            >修改</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 打印模板位置 -->
    <PrintBox
      :checkNum="10"
      :printRow="printList"
      :checkLabel="'infoList'"
      :isVertical="false"
      id="printBox"
    >
      <template slot="title" slot-scope="scope">
        <div>改进计划 STET/B/39-1</div>
      </template>
      <template slot-scope="scope">
        <!-- 表格  class  table-page  必须-->
        <table
          style="border-collapse: collapse; table-layout: fixed"
          border="1"
          cellspacing="0"
          class="table-page"
        >
          <tr style="height: 5mm">
            <td style="width: 30mm">序号</td>
            <td style="width: 40mm">部门</td>
            <td style="width: 30mm">填报人</td>
            <td style="width: 45mm">改进区域</td>
            <td style="width: 40mm">改进目标</td>
            <td style="width: 100mm">计划采取的改进措施、必要的纠正预防措施</td>
            <td style="width: 40mm">计划开始时间</td>
            <td style="width: 40mm">计划完成时间</td>
            <td style="width: 40mm">备注</td>
          </tr>
          <tr v-for="(e, i) in 10">
            <td>{{ scope.item.infoList[i] && i + 1 }}</td>

            <td>
              {{ scope.item.infoList[i] && scope.item.infoList[i].deptName }}
            </td>
            <td>
              {{ scope.item.infoList[i] && scope.item.infoList[i].user }}
            </td>
            <td>
              {{ scope.item.infoList[i] && scope.item.infoList[i].area }}
            </td>
            <td>
              {{ scope.item.infoList[i] && scope.item.infoList[i].improve }}
            </td>

            <td>
              {{ scope.item.infoList[i] && scope.item.infoList[i].target }}
            </td>
            <td>
              {{
                scope.item.infoList[i] &&
                parseTime(scope.item.infoList[i].startDate, "{y}-{m}-{d}")
              }}
            </td>
            <td>
              {{
                scope.item.infoList[i] &&
                parseTime(scope.item.infoList[i].endDate, "{y}-{m}-{d}")
              }}
            </td>
            <td>
              {{ scope.item.infoList[i] && scope.item.infoList[i].remark }}
            </td>
          </tr>
        </table>
        <!-- 底部信息位置 -->
        <div
          class="desc"
          style="display: flex;
          text-align:left;
            align-items: center;
            margin-top: 10px;
            }"
        >
          <div style="width: 30%; position: relative">
            计划编制人：
            <img
              style="width: 80px; position: absolute"
              :src="$VUE_APP_IMG_API + scope.item.esign"
            />
          </div>
          <div style="width: 30%; position: relative">
            批准人：<template v-if="CheckApprove(scope, 'pz').ShowImg">
              <img
                style="width: 80px; position: absolute"
                :src="CheckApprove(scope, 'pz').ApproveImg"
              />
            </template>
          </div>
          <div style="width: 30%">
            批准日期：{{ checkHistoryNode(scope, "pz").endTime }}
          </div>
        </div>
        <div class="page-bottom" style="page-break-after: always">
          <div class="desc">注：本表格自2022年5月1日起生效</div>
        </div>
      </template>
    </PrintBox>
  </div>
</template>

<script>
import {
  listmamagerImprove,
  delmamagerImprove,
} from "@/api/quality/manageAudit/improvePlan.js";
import printStyle from "@/utils/print.js";

export default {
  name: "improvePlan",
  data() {
    return {
      formData: { filePath: undefined },
      rules: {
        filePath: [
          {
            required: true,
            message: "附件不能为空",
            trigger: "change",
          },
        ],
      },

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditYear: null,
      },
      // 日期范围
      dateRange: [],
      openFile: false,
      type: 1,
      current: {},
      infos: [], //勾选的数据
      printList: [],
    };
  },
  created() {
    const str = sessionStorage.getItem('queryParams');
    if (str) {
      this.queryParams = JSON.parse(str);
      setTimeout(() => {
        sessionStorage.removeItem('queryParams');
      }, 500)
    }
    this.getList();
  },
  methods: {
    printBox() {
      //infos  勾选的数据 如果有勾选就打印勾选。
      if (this.infos.length) {
        this.printList = this.infos;
      } else {
        //反之打印当前整个列表
        this.printList = this.dataList;
      }
      setTimeout(() => {
        document.title = "改进计划 STET/B/39-1";

        this.$print({
          printable: "printBox", //打印区域id
          type: "html", //打印类型是html
          scanStyles: false,
          targetStyles: ["*"],
          style: this.workStyle(),
          onPrintDialogClose: () => {
            document.title = process.env.VUE_APP_TITLE;
          },
        });
      }, 500);
    },
    // 可以自定义样式  printStyle 是公共样式 切勿私自修改
    workStyle() {
      return `${printStyle}
        table,
        table tr th,
        table tr td {
          height:14mm;
          padding: 0px;
          font-size: 12px;
        }
        .desc{
        text-align: left; font-size: 12px; margin-top: 10px
      }
            .df {
                display: flex;
              }
      `;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.innerMamagerImproveId);
      this.single = selection.length != 1;
      this.infos = selection;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));

      const configId = row.innerMamagerImproveId || this.ids;
      this.$router.push("./addImprovePlan?isEdit=true&id=" + configId);
    },
    handleDetail(row) {
      sessionStorage.setItem('queryParams', JSON.stringify(this.queryParams));

      //
      this.$router.push({
        path: "/improvePlan/process/detail/" + row.piid,
        query: {
          definitionId: null,
          deployId: null,
          taskId: null,
          finished: false,
          id: row.innerMamagerImproveId,
        },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.innerMamagerImproveId || this.ids;
      let name = this.checkRow(
        configId,
        this.dataList,
        "innerMamagerImproveId",
        "DELETE",
        "year"
      );
      this.$modal
        .confirm('是否确认删除id为"' + configId + '"的数据项？')
        .then(function () {
          return delmamagerImprove(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleAdd() {
      this.$router.push("./addImprovePlan");
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listmamagerImprove(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startAuditDate",
          "endAuditDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleExport() {
      this.download(
        "system/mamagerImprove/export",
        {
          ...this.queryParams,
        },
        `改进计划记录表_${this.parseTime(
          new Date().getTime(),
          "{y}-{m}-{d}"
        )}.xlsx`
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.formData.type = this.type;
          this.formData.innerMamagerImproveId =
            this.current.innerMamagerImproveId;
          signFile(this.formData).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.openFile = false;
            this.getList();
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
